package TestModel;

import static org.junit.Assert.*;

import org.junit.Test;
import Task28.Command;
import Task28.Model;
import Task28.Result;

public class TestCd {
	Model tester;
	Result result = new Result();
	Command command = new Command();

	public void init() {
		try {
			tester = new Model();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	public void test1() {
		init();
		String[] args = { "C:\\Windows\\.." };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result", "C:\\", sResult);
	}

	@Test
	public void test2() {
		init();
		String[] args = { "C:\\Windows\\Driver Cache" };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result", "C:\\\\Windows\\Driver Cache", sResult);
	}
	
	@Test
	public void test3() {
		init();
		String[] args = { "C:\\Documents and Settings\\user\\..\\..\\Program Files" };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result", "C:\\\\Program Files", sResult);
	}
	
	@Test
	public void test4() {
		init();
		String[] args = { "C:\\Documents and Settings\\user\\..\\..\\" };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result", "C:\\", sResult);
	}
	
	@Test
	public void test5() {
		init();
		String[] args = { "C:\\\\" };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result", "C:\\", sResult);
	}
	@Test
	public void test6() {
		init();
		String[] args = { "C:\\..\\.." };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result", "C:\\", sResult);
	}
	
	@Test
	public void test7() {
		init();
		String[] args = { "C:\\Windows1\\.." };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result", "C:\\", sResult);
	}
	@Test
	public void test8() {
		init();
		String[] args = { "C:\\Windows1" };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result", "C:\\", sResult);
	}
	@Test
	public void test9() {
		init();
		String[] args = { "CQ:\\Windows1" };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result", "Path is file", sResult);
	}
	
	
	@Test
	public void testGetErrors() {
		init();
		String[] args = { "C:\\.." };
		command.setNameCommand("cd");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		int n;
		try {
			n = tester.getResult(command).getExceptions().size();
			assertTrue(n==0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
